texthandle: Fix positioning
authorMatthias Clasen <mclasen@redhat.com>
Tue, 3 Nov 2020 17:37:07 +0000 (12:37 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 3 Nov 2020 17:37:39 +0000 (12:37 -0500)
Use the same approach we use for popovers, using
gtk_widget_get_surface_allocation. It works.

Fixes: #3319
gtk/gtktexthandle.c

index 4353a6226d8f0c087f27a9310df7781a9111aa63..5953e4da5fb6877ba38d6f7635a0b1a27b9b98a2 100644 (file)
@@ -116,22 +116,19 @@ gtk_text_handle_present_surface (GtkTextHandle *handle)
   GdkPopupLayout *layout;
   GdkRectangle rect;
   GtkRequisition req;
-  double x, y;
+  GtkWidget *parent;
 
   gtk_widget_get_preferred_size (widget, NULL, &req);
   gtk_text_handle_get_padding (handle, &handle->border);
 
-  rect.x = handle->pointing_to.x;
-  rect.y = handle->pointing_to.y + handle->pointing_to.height - handle->border.top;
+  parent = gtk_widget_get_parent (widget);
+  gtk_widget_get_surface_allocation (parent, &rect);
+
+  rect.x += handle->pointing_to.x;
+  rect.y += handle->pointing_to.y + handle->pointing_to.height - handle->border.top;
   rect.width = req.width - handle->border.left - handle->border.right;
   rect.height = 1;
 
-  gtk_widget_translate_coordinates (gtk_widget_get_parent (widget),
-                                    gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW),
-                                    rect.x, rect.y, &x, &y);
-  rect.x = x;
-  rect.y = y;
-
   if (handle->role == GTK_TEXT_HANDLE_ROLE_CURSOR)
     rect.x -= rect.width / 2;
   else if ((handle->role == GTK_TEXT_HANDLE_ROLE_SELECTION_END &&